<template>
  <div class="register">
    <div class="register-form">
      <h1>注册</h1>
      <input type="text" placeholder="请输入用户名" v-model="username" />
      <input type="password" placeholder="请输入密码" v-model="password" />
      <button @click="register">注册</button>
    </div>
  </div>
</template>


<style scoped>
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.register-form {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  box-shadow: 10px 10px 10px 0 rgba(0, 0, 0, 0.1);
  background-color: #d4e8ff;
  padding: 40px 20px;
  border-radius: 10px;
  width: 400px;
  height: 350px;
}

.register-form input {
  width: 300px;
  height: 30px;
  border-radius: 10px;
  border: 2px solid #b2b2b2;
}

.register-form button {
  background-color: #007bff;
  color: #fff;
  cursor: pointer;
  width: 100px;
  height: 30px;
  border-radius: 10px;
  border: none;
}
</style>

<script>
import axios from 'axios';
export default {
  data() {
    return {
      username: "",
      password: "",
    }
  },
  methods: {
    register() {
      axios.post('http://localhost:3080/user/register', {
        username: this.username,
        password: this.password
      }
      ).then(res => {
        if(res.data === "注册成功"){
          alert("注册成功");
          this.$router.push('/task');
        }else{
          alert(res.data);
        }
      })
    }
  }
}
</script>
